/**
 *  一句话思路：
    算法描述：
    解决所需数据结构+算法：
**/
#include<iostream>
#include<cmath>
using namespace std;

int gcd(int a, int b) {
    if(a == 0)  return b;
    return gcd(b, a%b);
}

int main() {
    int T, M;
    cin >> T >> M;
    while(T--) {
        int a, b, c, delta, p, q, r, s=1;
        cin >> a >> b >> c;
        delta = b * b - 4 * a * c;
        if(delta < 0) {
            cout << "NO" << endl;
            continue;
        }
        p = gcd(-b, 2*a);
        for(int i=sqrt(M)+1; i>0; i++) {
            if(delta % (i*i) == 0) {
                r = delta / i / i;
                s = i;
                break;
            }
        }
        q = gcd(s, 2 * a);
        // 输出部分
        if(b != 0) {
            if(2*a/p == 1)  cout << -b/p;
            else cout << -b/p << "/" << 2*a/p;
        }
        if(delta != 0) {
            if(b != 0)  cout << "+";
            if(s/a/2 == 1)    cout << "sqrt(" << r << ")";
            else if(s%(2*a) == 0)    cout << s/q << "*sqrt(" << r << ")";
            else if((2*a)%s == 0)    cout << "*sqrt(" << r << ")/" << (2*a)/q;
            else cout << s/q << "*sqrt(" << r << ")/" << (2*a)/q;
        }
        cout << endl;
    }
    return 0;
}